package com.relytosoft.mizar.media.display.services.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.relytosoft.dubhe.common.core.object.ResponseResult;
import com.relytosoft.dubhe.common.log.annotation.OpLog;
import com.relytosoft.dubhe.common.log.enums.OpTypeEnum;
import com.relytosoft.mizar.media.display.api.entity.Preset;
import com.relytosoft.mizar.media.display.api.pojo.dto.PtzPresetDto;
import com.relytosoft.mizar.media.display.services.service.PresetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 云台预置点控制器
 *
 * @author hj
 * @version 1.0
 * @date 2022/4/8 13:39
 * @ClassName PtzPresetController
 */
@Validated
@RestController
@RequestMapping("/display/preset")
@Api(tags = "云台预置点控制器")
public class PtzPresetController {
    @Resource
    private PresetService presetService;

    @ApiOperation(value = "添加预置点")
    @PostMapping("/add")
    @SaCheckPermission("display:preset:insert")
    @OpLog(msg = "新增预置点",opType = OpTypeEnum.UPDATE)
    public ResponseResult<Void> add(@RequestBody @Valid PtzPresetDto preset){
        boolean save = presetService.addPreset(preset);
        if (save) {
            return ResponseResult.ok();
        }
        return ResponseResult.fail();
    }

    @ApiOperation("修改预置点")
    @PutMapping("/edit")
    @SaCheckPermission("display:preset:update")
    @OpLog(msg = "修改预置点",opType = OpTypeEnum.UPDATE)
    public ResponseResult<Void> edit(@RequestBody @Valid PtzPresetDto preset){
        boolean update = presetService.updateByPreset(preset);
        if (update){
            return ResponseResult.ok();
        }
        return ResponseResult.fail();
    }

    @ApiOperation(value = "删除预置点信息")
    @DeleteMapping("{id}/delete")
    @SaCheckPermission("display:preset:delete")
    @OpLog(msg = "删除预置点",opType = OpTypeEnum.UPDATE)
    public ResponseResult<Void> delete(@PathVariable Integer id){
        boolean delete = presetService.deleteById(id);
        if (delete) {
            return ResponseResult.ok();
        }
        return ResponseResult.fail();
    }

    @ApiOperation(value = "查询预置点信息")
    @GetMapping("/list")
    @SaCheckPermission("display:preset:list")
    @OpLog(msg = "根据通道id查询",opType = OpTypeEnum.SELECT)
    public ResponseResult<List<PtzPresetDto>> getList(@RequestParam(required = true) Integer channelId){
        List<PtzPresetDto> presets = presetService.selectPresetListById(channelId);
        return ResponseResult.ok(presets);
    }



}
